import java.awt.*;
import java.awt.event.MouseEvent;

public class DessinTriangleHG extends Dessin{
	private static final long serialVersionUID = 1L;

	Shape shape;
	
	int xDebutMvt;
	int yDebutMvt;
	
	public boolean contains(int x, int y)
	{
		if(shape == null || ! shape.getBounds().getSize().equals(getSize()))
		{
			int x1 = xDebut - this.getX();
			int y1 = yDebut - this.getY();
			
			int x2 = this.getWidth() - x1;
			int y2 = y1;
			
			int x3 = x1;
			int y3 = this.getHeight() - y1;
			
			
			int[] xTmp = {x1,x2,x3};
			int[] yTmp = {y1,y2,y3};
			
			//int[] xTmp = {0,this.getWidth(),0};
			//int[] yTmp = {0,0,this.getHeight()};
			shape = new Polygon(xTmp, yTmp, 3);
		}
		return shape.contains(x, y);
	}
	
	public void paint(Graphics g)
	{
		this.setOpaque(false);
		g.setColor(defaultColor);
		
		int x1 = xDebut - this.getX();
		int y1 = yDebut - this.getY();
		
		int x2 = this.getWidth() - x1;
		int y2 = y1;
		
		int x3 = x1;
		int y3 = this.getHeight() - y1;
		
		
		int[] x = {x1,x2,x3};
		int[] y = {y1,y2,y3};
		g.fillPolygon(x, y, 3);
	}
	
	public void mouseDragged(MouseEvent e) {
		xDebut = xDebut + (e.getX() - xDebutMvt);
		yDebut = yDebut + (e.getY() - yDebutMvt);
		DessinTriangleHG.this.setBounds(DessinTriangleHG.this.getX() + (e.getX() - xDebutMvt), DessinTriangleHG.this.getY() + (e.getY() - yDebutMvt), DessinTriangleHG.this.getWidth(), DessinTriangleHG.this.getHeight());
		
		repaint();
	}


	public void mousePressed(MouseEvent e) {
		xDebutMvt = e.getX();
		yDebutMvt = e.getY();
		
	}
}
